package com.team11.server.controller.admin;

import com.team11.server.pojo.P_C_S_T_information;
import com.team11.server.service.admin.Admin_InsertSInP_Service;
import com.team11.server.service.admin.Admin_UpdatePleader_Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@Api(tags = "管理员接口")
public class Admin_InsertSInP_Controller {
    @Autowired
    private Admin_InsertSInP_Service admin_insertSInP_service;
    @Autowired
    private Admin_UpdatePleader_Service admin_updatePleader_service;
    @ApiOperation("点击新增成员接口，需要选择小组id")
    @PostMapping("/selAllS_NotInP")
    public List<P_C_S_T_information> selAllS_NotInP(Integer pId){
        return admin_insertSInP_service.selAllS_NotInP(pId);
    }

    @ApiOperation("项目组新增成员，可多加(需要小组id和学号)")
    @PostMapping("/InsertSInP")
    public String insertSInP(Integer pId,@RequestParam(value = "sNumbers" ,required=false)List<String> sNumbers){
        HashMap<String,Object> map=new HashMap<>();
        map.put("pId",pId);
        map.put("NewPid",pId);
        for (String sNumber:sNumbers){
            map.put("sNumber",sNumber);
            String s=admin_updatePleader_service.SelSInP(map);
            System.out.println(s);
            if ("学生不在此小组".equals(s)) {
                admin_insertSInP_service.insertSInP(map);
            }
            else return  "学生已在该小组";
        }
        return "命令执行成功";

    }

}
